﻿using SqlSugar;
using Store.Manager.ERP.Domain;
using Store.Manager.ERP.Domain.Entities;
using Store.Manager.ERP.Domain.Repositories;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Store.Manager.ERP.Infrastructure
{
    public class InventoryRepository : Repository<Inventory>, IInventoryRepository
    {
        private readonly IUnitOfWork _unitOfWork;

        public InventoryRepository(ISqlSugarClient db, IUnitOfWork unitOfWork) : base(db)
        {
            _unitOfWork = unitOfWork;
        }
        public IUnitOfWork UnitOfWork => _unitOfWork;

        public async Task AddAsync(Inventory inventory)
        {
            await base.InsertAsync(inventory);
        }

        public async Task<Inventory> GetByOrganizationAndProductAsync(string organizationCode, string productCode)
        {
            return await base.GetFirstAsync(i => i.OrganizationCode == organizationCode && i.ProductCode == productCode);
        }

        public ISqlSugarClient GetDbContext()
        {
            return base.Context;
        }

        Task IInventoryRepository.UpdateAsync(Inventory inventory)
        {
            return UpdateAsync(inventory);
        }
    }
}
